﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Web.Services;

namespace letGo.Account
{
    public partial class Regist : System.Web.UI.Page
    {

        protected string Action = "";
        
        
        protected UserLoginInfo _UserLoginInfo = new UserLoginInfo();//创建对象




        protected void Page_Load(object sender, EventArgs e)
        {
            Init_WebControls();
        }


        public void Init_WebControls()
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["Action"]))//获取form的Action中的参数
                {
                    Action = Request.QueryString["Action"].Trim().ToLower();//去掉空格并变小写
                }
                switch (Action)
                {
                    case "regist":
                        myBaseClass readData = new myBaseClass();
                        string str="select username from [user] where username=N'" +Request.Form["username"].ToString()+"'";
                        if(readData.isFound(str))
                        {
                            Label registMessage = (Label)RegistControl1.FindControl("RegistMessage");
                            registMessage.Text = "用户名已存在！";
                        }
                         else if (!string.IsNullOrEmpty(Request.Form["UserName"]) && !string.IsNullOrEmpty(Request.Form["PassWord"]))//获取form中的参数
                        {
                            _UserLoginInfo.UserName = Request.Form["username"].ToString();
                            _UserLoginInfo.UserPassword = Request.Form["password"].ToString();
                            _UserLoginInfo.UserEmail = Request.Form["email"].ToString();


                            Session["username"] = _UserLoginInfo.UserName;
                            
                            string sql = @"insert [user](username,password,email,RegistedTime,usertype) values(@username,@password,@email,@RegistedTime,@usertype)";
                         
                            
                            readData.readDataSet(sql, _UserLoginInfo);

                            
                            Label registMessage = (Label)RegistControl1.FindControl("RegistMessage");
                            registMessage.Text = "注册成功，将为您自动跳转！";

                            Response.Write("<meta http-equiv=refresh content='1;URL=../Account/FillInfo.aspx'>");

                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }//Init_WebControls()


        [WebMethod]
        public static string checkUserName(string userName)
        {
            string msg;
            string str = "select username from [user] where username=N'" +userName+"'";
            myBaseClass IsFound = new myBaseClass();

            //string userName = Request.QueryString["userName"].ToString();
            if (IsFound.isFound(str))
            {
                msg=" 用户名已经存在！ ";
            }
            else
            {
                msg = " 您可以使用此用户名！ ";
            }
            return msg;
        }







    }
}